#!/usr/bin/env python3
"""
测试修复后的分段限制
"""

import asyncio
from pathlib import Path
from app.services.large_video_analyzer import LargeVideoAnalyzer

async def test_fixed_analysis():
    """测试修复后的大视频分析"""
    
    video_path = Path("uploads/24e6864f-95e0-4ae5-9406-ad9b8d66b567.mp4")
    
    if not video_path.exists():
        print(f"❌ 视频文件不存在: {video_path}")
        return
    
    print(f"🧪 测试修复后的大视频分析")
    print(f"📹 视频文件: {video_path.name}")
    
    analyzer = LargeVideoAnalyzer()
    
    try:
        # 测试拆分功能
        print(f"\n1️⃣ 测试视频拆分...")
        split_result = await analyzer.video_splitter.split_video_by_duration(
            video_path, 
            segment_duration=60,
            max_segments=50,  # 使用新的限制
            min_segment_duration=10
        )
        
        segments_count = len(split_result.get('segments', []))
        print(f"   拆分结果: {segments_count} 个片段")
        print(f"   拆分状态: {'✅ 成功' if segments_count > 0 else '❌ 失败'}")
        
        if segments_count > 0:
            print(f"   前3个片段:")
            for i, segment in enumerate(split_result['segments'][:3]):
                print(f"     {i+1}. {segment['filename']} ({segment.get('duration', 0):.1f}s)")
        
        # 测试完整分析流程（但不实际调用AI服务）
        print(f"\n2️⃣ 测试分析流程初始化...")
        
        # 模拟分析请求
        prompt = "请分析视频内容"
        
        # 只测试到拆分阶段，不进行实际AI分析
        print(f"   提示词: {prompt}")
        print(f"   ✅ 分析流程初始化成功")
        
    except Exception as e:
        print(f"❌ 测试失败: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    asyncio.run(test_fixed_analysis())